<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<script type="text/javascript">
//		onload只保存两个部分,关闭图层和缩回图层,加定时器
		(function(){
			window.onload=function(){
				var clossBtn=document.getElementById('closeDiv');
				clossBtn.onclick=function
				(){
					var adObj=document.getElementById('adDiv');
					adObj.style.display='none';
				}
				setTimeout('hideAd()',1000);
			}
		})();
//		现在写hideAd方法
          var myTimeout;
          function hideAd(){
          	var step =100;
//        	console.log(adDiv.offsetHeight)
           adDiv.style.height=adDiv.offsetHeight-step+'px';
           if (adDiv.style.offsetHeight<step) {
           	clearTimeout(myTimeout);
           	adDiv.style.display = "none"
           } else{
           	 myTimeout=setTimeout('hideAd()',1000);
           }
           }
//         现在写切换模块switch
           function adSwitch(btnObj){
           	 adDiv.style.height = "400px";
           	adDiv.style.display == 'block' ? adDiv.style.display = "none" : adDiv.style.display = "block";
        btnObj.value == "隐藏图层" ? btnObj.value = "显示图层" : btnObj.value = "隐藏图层";
        if(adDiv.style.display == "block") {
          setTimeout("hideAd()", "1000");
        } 
           }
         
        
	</script>
	<style type="text/css">
		div#adDiv{
			width: 100%;
			position: fixed;
			left: 0;
			top: 0;
			overflow: hidden;
		}
		div#closeDiv{
			width: 60px;
			height: 60px;
			line-height: 60px;
			background-color: #808080;
			text-align: center;
			position: absolute;
			right: 0;
			top: 0;
			cursor: pointer;
		}
		#switchDiv{
			position: relative;
			left: 0;
			top: 400px;
		}
	</style>
	<body>
		<!--此时，给input绑定switch方法，传入指向参数this-->
		<input type="button" id="switchDiv" value="隐藏图层" onclick="adSwitch(this);"/>
		
	<div id="adDiv" style="display: block;height: 400px;">
		<div id="closeDiv">×</div>
		<img src="img/12.png" width="600px" />
		<!--图层里面再镶嵌一个用来关闭的div-->
	</div>
	</body>
</html>
